// File: LoginView.java

package view;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import model.Sale;

/**
 * Creates a view to delete user.
 *
 * @author Tobias Robinson
 */
public class EditPromotionView extends JDialog implements ActionListener {

    //input to pass to UCLoginUser
    private String discount = null;
    private String tickets = null;

    //components of the login window
    private JTextField discountField = new JTextField(10);
    private JTextField ticketsField = new JTextField(10);
    private JLabel discountLabel = new JLabel("Enter Discount:  ");
    private JLabel ticketsLabel = new JLabel("Enter Tickets: ");
    private JButton setButton = new JButton("Set Discount");


    /**
     * Creates a view to login user.
     *
     * @param parent tells view to run over main window
     */
    public EditPromotionView(JFrame parent) {
        super(parent, "Edit Promotion", true);
        setResizable(false);

        //content pane for login window
        JPanel promotionPane = new JPanel();
        setContentPane(promotionPane);

        //user GridBag layout
        GridBagLayout gb = new GridBagLayout();
        GridBagConstraints c = new GridBagConstraints();
        promotionPane.setLayout(gb);
        promotionPane.setBorder(BorderFactory.createEmptyBorder(12, 12, 11, 11));

        // place the gst label
        c.gridwidth = GridBagConstraints.RELATIVE;
        c.insets = new Insets(10, 10, 5, 0);
        gb.setConstraints(discountLabel, c);
        promotionPane.add(discountLabel);

        // place the text field for gst
        c.gridwidth = GridBagConstraints.REMAINDER;
        c.insets = new Insets(10, 0, 5, 10);
        gb.setConstraints(discountField, c);
        promotionPane.add(discountField);

                // place the gst label
        c.gridwidth = GridBagConstraints.RELATIVE;
        c.insets = new Insets(10, 10, 5, 0);
        gb.setConstraints(ticketsLabel, c);
        promotionPane.add(ticketsLabel);

        // place the text field for gst
        c.gridwidth = GridBagConstraints.REMAINDER;
        c.insets = new Insets(10, 0, 5, 10);
        gb.setConstraints(ticketsField, c);
        promotionPane.add(ticketsField);

        // place the login button
        c.gridwidth = GridBagConstraints.REMAINDER;
        c.insets = new Insets(10, 10, 5, 10);
        c.anchor = GridBagConstraints.CENTER;
        gb.setConstraints(setButton, c);
        promotionPane.add(setButton);

        // end of layout

        // Register password field and OK button with action event handler.
        // An action event is generated when the return key is pressed while
        // the cursor is in the password field or when the OK button is pressed.
        setButton.addActionListener(this);

        //place the cursor in the username field
        discountField.requestFocus();
    }

    /**
     * When user click button or presses enter processes information
     *
     * @param e event type
     */
    public void actionPerformed(ActionEvent e) {
            discount = new String(discountField.getText());
            tickets = new String(ticketsField.getText());
            //set the value
            Sale.setPromotion(discount, tickets);
            //close window
            dispose();
    }
}

